package freshmanspecial.mredrock.com.welcomefreshman.Fragment;

import android.graphics.Color;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;

import java.util.ArrayList;
import java.util.List;


import freshmanspecial.mredrock.com.welcomefreshman.Base.BaseFragment;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.CircleChartData;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.FailRatioBean;
import freshmanspecial.mredrock.com.welcomefreshman.Model.DataModel;
import freshmanspecial.mredrock.com.welcomefreshman.MyChart.CircleChart;
import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by Administrator on 2017/8/3 0003.
 */

public class DataFragmentTwo extends BaseFragment {
    private List<CircleChartData> defaultDatas = new ArrayList<>();
    private static  List<String> options1Items = new ArrayList<>();
    private static  List<String> options1Items2 = new ArrayList<>();
    private OptionsPickerView pvOptions,pvOptions2;
    private TextView mTView,zhuanyeText;
    private CircleChart chart ;
    private RelativeLayout relativeLayout;
    private int fuck=0;
    private CircleChartData data1,data2,data3;
    private TextView project1,project2,project3;
    private  FailRatioBean failRatioBean;
    @Override
    protected void addDefaultData() {
        defaultDatas.clear();
         data1 = new CircleChartData();
        data1.setProportion((float) 0.50);
        data1.setCircleColor(Color.parseColor("#B9E5FE"));
        data1.setCircleStrokeColor(Color.parseColor("#7AC8EF"));
        data1.setBackgroundColor(Color.parseColor("#F8FCFF"));
        data1.setBackgroundStrokeColor(Color.parseColor("#D4F5FF"));
        data2 = new CircleChartData();
        data2.setProportion((float) 0.60);
        data2.setCircleColor(Color.parseColor("#9EFCEE"));
        data2.setCircleStrokeColor(Color.parseColor("#6CEAD5"));
        data2.setBackgroundColor(Color.parseColor("#F8FFFE"));
        data2.setBackgroundStrokeColor(Color.parseColor("#D7FFF9"));
         data3 = new CircleChartData();
        data3.setProportion((float) 0.75);
        data3.setCircleColor(Color.parseColor("#FBFEB9"));
        data3.setCircleStrokeColor(Color.parseColor("#ECD76C"));
        data3.setBackgroundColor(Color.parseColor("#FFFFFB"));
        data3.setBackgroundStrokeColor(Color.parseColor("#FDF9E7"));
        defaultDatas.add(data1);
        defaultDatas.add(data2);
        defaultDatas.add(data3);
    }

    @Override
    protected void initView() {
        project1 = $(R.id.project1);
        project2 = $(R.id.project2);
        project3 = $(R.id.project3);

        chart = $(R.id.project_circle);
        zhuanyeText = $(R.id.zhuanye_text);
        relativeLayout = $(R.id.zhuanye_relativeLayout);
        chart.setCircleChartData(defaultDatas);
        setupViews();
        setList();
    }

    private void setList() {
        options1Items.clear();
        options1Items.add("通信与信息工程学院");
        options1Items.add("光电工程学院");
        options1Items.add("经济管理学院");
        options1Items.add("计算机科学与技术学院");
        options1Items.add("外国语学院");
        options1Items.add("生物信息学院");
        options1Items.add("网络空间安全与信息法学院");
        options1Items.add("自动化学院");
        options1Items.add("先进制造工程学院");
        options1Items.add("体育学院");
        options1Items.add("理学院");
        options1Items.add("传媒艺术学院");
        options1Items.add("软件工程学院");
        options1Items.add("国际半导体学院");
        options1Items.add("国际学院");
    }
    @Override
    protected int getResourceId() {
        return R.layout.special_2017_data_fail_fragment;
    }
    private void setOptionsPicker(final List<String> options1Item, final TextView text) {
         pvOptions = new  OptionsPickerView.Builder(getActivity(), new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3 ,View v) {
                //返回的分别是三个级别的选中位置
                final String s =  options1Item.get(options1);
                    text.setText("    "+s);
                zhuanyeText.setText("    请选择专业");
                options1Items2.clear();
                DataModel dataModel = new DataModel();
                dataModel.getFailRatio(new DataModel.OnGetData() {
                    @Override
                    public void onFinish(Object dataBean) {
                        final FailRatioBean bean = (FailRatioBean) dataBean;
                        for(int i=0;i<bean.getData().size();i++)
                        {

                            if(bean.getData().get(i).getCollege().equals(s))
                            {
                                if(fuck ==0)
                                {
                                    options1Items2.add(bean.getData().get(i).getMajor());
                                    fuck++;
                                }

                                int count=0;

                                for(int m=0;m<options1Items2.size();m++)
                                {

                                    if(options1Items2.get(m).equals(bean.getData().get(i).getMajor()))
                                    {
                                        count++;
                                        break;
                                    }
                                }
                                if(count==0)
                                {
                                    options1Items2.add(bean.getData().get(i).getMajor());
                                }
                            }
                        }
                    }
                });

            }
        })
                .setSubmitText("确定")//确定按钮文字
                .setCancelText(" ")//取消按钮文字
                .setSubCalSize(20)//确定和取消文字大小
                .setSubmitColor(Color.parseColor("#81C0FE"))//确定按钮文字颜色
                .setTitleBgColor(Color.parseColor("#00000000"))//标题背景颜色 Night mode
                .setContentTextSize(18)//滚轮文字大小
                .setTextColorCenter(Color.WHITE)//设置选中项的颜色
                .setTextColorOut(Color.parseColor("#81C0FE"))
                .isCenterLabel(true) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setOutSideCancelable(true)//点击外部dismiss default true
                .build();
        pvOptions.setPicker(options1Item);
    }
        private void setOptions1Picker2(final List<String> options1Item, final TextView text){
            pvOptions2 = new  OptionsPickerView.Builder(getActivity(), new OptionsPickerView.OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int option2, int options3 ,View v) {
                    //返回的分别是三个级别的选中位置
                    final String s =  options1Item.get(options1);
                    zhuanyeText.setText("    "+s);
                    DataModel dataModel = new DataModel();
                    dataModel.getFailRatio(new DataModel.OnGetData() {
                        @Override
                        public void onFinish(Object dataBean) {
                            failRatioBean = (FailRatioBean) dataBean;
                            for(int n = 0; n<failRatioBean.getData().size();n++)
                            {
                                if(failRatioBean.getData().get(n).getMajor().equals(s))//获取当前选择的专业
                                {//前后三个科目是所要的
                                    int o=0;
                                    defaultDatas.clear();
                                    data1.setProportion(Float.parseFloat(failRatioBean.getData().get(n+o).getRatio()));
                                    project1.setText(failRatioBean.getData().get(n+o).getCourse());
                                    o++;
                                    data2.setProportion(Float.parseFloat(failRatioBean.getData().get(n+o).getRatio()));
                                    project2.setText(failRatioBean.getData().get(n+o).getCourse());
                                    o++;
                                     data3.setProportion(Float.parseFloat(failRatioBean.getData().get(n+o).getRatio()));
                                    project3.setText(failRatioBean.getData().get(n+o).getCourse());
                                    defaultDatas.add(data1);
                                    defaultDatas.add(data2);
                                    defaultDatas.add(data3);
                                    chart.setCircleChartData(defaultDatas);
                                }
                            }
                        }
                    });

                }
            })
                    .setSubmitText("确定")//确定按钮文字
                    .setCancelText(" ")//取消按钮文字
                    .setSubCalSize(20)//确定和取消文字大小
                    .setSubmitColor(Color.parseColor("#81C0FE"))//确定按钮文字颜色
                    .setTitleBgColor(Color.parseColor("#00000000"))//标题背景颜色 Night mode
                    .setContentTextSize(18)//滚轮文字大小
                    .setTextColorCenter(Color.WHITE)//设置选中项的颜色
                    .setTextColorOut(Color.parseColor("#81C0FE"))
                    .isCenterLabel(true) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                    .setOutSideCancelable(true)//点击外部dismiss default true
                    .build();
            pvOptions2.setPicker(options1Item);

        }


    private void setupViews() {
        mTView = $(R.id.tv_value2);
        mTView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setOptionsPicker(options1Items,mTView);
                relativeLayout.setVisibility(View.VISIBLE);
                pvOptions.show();

            }
        });
        zhuanyeText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setOptions1Picker2(options1Items2,zhuanyeText);
                pvOptions2.show();
            }
        });
    }
}
